package com.example.donghuihui.androidframe.basewebview;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
import com.example.donghuihui.androidframe.utils.NetUtil;

import java.util.Map;

/**
 * 自定义WebView父类
 */
public class BaseWebView extends WebView {
    public BaseWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        setWebViewClient(new BaseWebViewClient() {

            @Override
            protected boolean onPreLoad(WebView view, String url) {
                return false;
            }
        });
    }

    @Override
    public void loadUrl(String url) {
        if (NetUtil.isConnected(getContext())) {
            super.loadUrl(url);
        } else {
            super.loadUrl("file:///android_asset/nowifi.htm");
        }
    }

    @Override
    public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
        if (NetUtil.isConnected(getContext())) {
            super.loadUrl(url, additionalHttpHeaders);
        } else {
            super.loadUrl("file:///android_asset/nowifi.htm");
        }
    }

    @Override
    public void goBack() {
        super.goBack();
    }
}
